package com.authorization.project.authorization.service.impl;

import java.util.List;
import com.authorization.common.utils.DateUtils;
import com.authorization.project.authorization.domain.Authorization;
import com.authorization.project.authorization.mapper.AuthorizationMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.authorization.project.authorization.mapper.AuthorizationLogMapper;
import com.authorization.project.authorization.domain.AuthorizationLog;
import com.authorization.project.authorization.service.IAuthorizationLogService;

/**
 * 授权日志Service业务层处理
 * 
 * @author 李晓雷
 * @date 2020-05-11
 */
@Service
@Slf4j
public class AuthorizationLogServiceImpl implements IAuthorizationLogService 
{
    @Autowired
    private AuthorizationLogMapper authorizationLogMapper;

    @Autowired
    private AuthorizationMapper authorizationMapper;

    /**
     * 查询授权日志
     * 
     * @param id 授权日志ID
     * @return 授权日志
     */
    @Override
    public AuthorizationLog selectAuthorizationLogById(Long id)
    {
        return authorizationLogMapper.selectAuthorizationLogById(id);
    }

    /**
     * 查询授权日志列表
     * 
     * @param authorizationLog 授权日志
     * @return 授权日志
     */
    @Override
    public List<AuthorizationLog> selectAuthorizationLogList(AuthorizationLog authorizationLog)
    {
        return authorizationLogMapper.selectAuthorizationLogList(authorizationLog);
    }

    /**
     * 新增授权日志
     * 
     * @param authorizationLog 授权日志
     * @return 结果
     */
    @Override
    public int insertAuthorizationLog(AuthorizationLog authorizationLog)
    {
        //验证机器码
        Authorization authorization = authorizationMapper.selectAuthorizationById(authorizationLog.getUserid());
        if(!authorization.getMachineCode().equals(authorizationLog.getMachineCode())){
            log.info("机器码不同，授权机器码{}, 收集日志机器码{}",authorization.getMachineCode(), authorizationLog.getMachineCode());
        }
        authorizationLog.setCreateTime(DateUtils.getNowDate());
        return authorizationLogMapper.insertAuthorizationLog(authorizationLog);
    }

    /**
     * 修改授权日志
     * 
     * @param authorizationLog 授权日志
     * @return 结果
     */
    @Override
    public int updateAuthorizationLog(AuthorizationLog authorizationLog)
    {
        authorizationLog.setUpdateTime(DateUtils.getNowDate());
        return authorizationLogMapper.updateAuthorizationLog(authorizationLog);
    }

    /**
     * 批量删除授权日志
     * 
     * @param ids 需要删除的授权日志ID
     * @return 结果
     */
    @Override
    public int deleteAuthorizationLogByIds(Long[] ids)
    {
        return authorizationLogMapper.deleteAuthorizationLogByIds(ids);
    }

    /**
     * 删除授权日志信息
     * 
     * @param id 授权日志ID
     * @return 结果
     */
    @Override
    public int deleteAuthorizationLogById(Long id)
    {
        return authorizationLogMapper.deleteAuthorizationLogById(id);
    }
}
